<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>监听watch-demo</title>
</head>
<body>
<div id="application">
    <input v-model.lazy="searchText">
    <span>{{searchText}}</span>
</div>
<script src="../vue3.js"></script>
<script>
    const app = {
        data() {
            return {
                searchText: "hello",
            }
        },
       watch: {
           searchText(newValue, oldValue) {
               console.log(newValue, oldValue)
               if (newValue.length > 10) {
                   alert("文本过长")
                   this.searchText = ""
               }
           }
       }
    }
    Vue.createApp(app).mount("#application")
</script>
</body>
</html>